package com.wendu.oa.api;

import com.wendu.oa.common.Constants;
import com.wendu.oa.common.Result;
import com.wendu.oa.dto.MyDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@RestController
public class TestController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private LeaveApi leaveApi;



    @RequestMapping("/test4")
    public Result test4(@RequestHeader(Constants.HEADER_TOKEN) String token, MyDto myDto){
        return leaveApi.getResult3(token,myDto);
    }

    @RequestMapping("/test3")
    public Result test3(@RequestHeader(Constants.HEADER_TOKEN) String token,Integer pageNum,Integer pageSize){
        return leaveApi.getResult2(token,pageNum,pageSize);
    }

    @RequestMapping("/test2")
    public Result test2(){
        return leaveApi.getResult();
    }

    @RequestMapping(value="/test",produces = "application/json;charset=UTF-8")
    public String test(){

        //return leaveApi.getHello();


        HttpHeaders headers = new HttpHeaders();
        headers.set("Token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJVU0VSSUQiOiJhZG1pbiIsIlVTRVJOQU1FIjoi55So5oi3MSIsImV4cCI6MTYzMzY4Njc0NX0.2CKiu1YnzcT9y8AHE55luTvVG_hyCUkSZXse0B0wyok");

//        MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();
//        paramMap.add("pageSize", 16);

        //HttpEntity httpEntity = new HttpEntity(paramMap,headers);
        HttpEntity httpEntity = new HttpEntity(headers);

        ResponseEntity<String> info = restTemplate.exchange("http://leave/apprev/app?pageSize=19", HttpMethod.GET,httpEntity,String.class);
        //Result info = restTemplate.getForObject("http://leave/apprev/app", String.class,httpEntity);


        return info.getBody();


    }
}
